﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using Hi_Baidu.ProcessModel;

namespace Hi_Baidu.Timer
{
    /// <summary>
    ///     提供了登陆操作的计时操作和后续处理
    /// </summary>
    class LoginTimeOutEvent : TimeOutEvent
    {
        private byte[] Username;
        private byte[] Password;
        private Window1 WinLogin;
        private byte[] LoginState;

        public LoginTimeOutEvent(String Key, int Interval, int TryCount, byte[] Username, byte[] Password, byte[] LoginState, Window1 WinLogin)
            : base(Key, Interval, TryCount)
        {
            this.Username = Username;
            this.Password = Password;
            this.LoginState = LoginState;
            this.WinLogin = WinLogin;
            this.OnTick += new EventHandler<EventArgs>(LoginTimeOutEvent_OnTick);
            this.OnTryFull += new EventHandler<EventArgs>(LoginTimeOutEvent_OnTryFull);
        }

        void LoginTimeOutEvent_OnTryFull(object sender, EventArgs e)
        {
            System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new PUBLIC_DELEGATE(Globle.ShowWindow));
        }

        void LoginTimeOutEvent_OnTick(object sender, EventArgs e)
        {
            byte[] Package = LoginProcessModel.LoginParser(Username, Password, LoginState);
            if (Package != null)
            {
                LoginProcessModel.Login(Package);
            }
        }
    }
}
